package study.produceOrConsume;

public class Consume implements Runnable {
	private String flag="";
	public Consume(String flag)
	{
		this.flag=flag;
	}
	/**
	 * 消费者从店员取产品
	 */
	public  void consume() {
		synchronized (flag) {
		
		if (Store.getProduct() <= Store.MIN_PRODUCT) {
			try {
				System.out.println("缺货,稍候再取");
				flag.wait();
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else {

			System.out.println("消费者取走了第" + Store.getProduct() + "个产品.");
			Store.operate("jianjian");
			try {
				flag.notifyAll(); // 通知等待去的生产者可以生产产品了
				flag.wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			
		}
		
		}
		
	}

	public void run() {
		while (true)
			consume();
	}

}
